﻿using System;
using System.Threading;
using System.Windows.Controls;

namespace FrontDisplay.Weather
{
    /// <summary>
    /// Interaction logic for WeatherItemControl.xaml
    /// </summary>
    public partial class WeatherItemControl : UserControl
    {
        public WeatherItemControl()
        {
            InitializeComponent();
        }

        public void Update(WeatherItem weather)
        {
            if (weather == null)
            {
                Date.Text = string.Empty;
                Month.Text = string.Empty;
                Temperature.Text = string.Empty;
                WeatherCondition.Content = null;
                return;
            }

            if (DateTime.Now.DayOfYear == weather.Date.DayOfYear)
            {
                Date.Text = string.Empty;
                Month.Text = Def.Localization.GetString("Weather.Today");
            }
            else
            if ((weather.Date > DateTime.Now) && (weather.Date - DateTime.Now <= new TimeSpan(TimeSpan.TicksPerDay)))
            {
                Date.Text = string.Empty;
                Month.Text = Def.Localization.GetString("Weather.Tomorrow");
            }
            else
            {
                Date.Text = weather.Date.Day.ToString();
                Month.Text = weather.Date.ToString("d MMMM", Thread.CurrentThread.CurrentUICulture.DateTimeFormat).Remove(0, 2).Trim().ToLower();
            }
            Temperature.Text = weather.ReadableTemperature;
            WeatherCondition.Content = weather.Image;
            //WeekDay.Text = Def.Localization.CurrentCulture.DateTimeFormat.DayNames[(int) weather.Date.DayOfWeek];
            WeekDay.Text = Thread.CurrentThread.CurrentUICulture.DateTimeFormat.DayNames[(int)weather.Date.DayOfWeek];
        }

    }
}
